<?php 
include_once 'model/user/user_create.php';
    
    $user = new users();
    $result = $user->select();
    $i = 0;
    $numPage = 4;
    if(!$_GET["page"]){
        $page = 1;
    }else if((int)$_GET["page"]){
        $page = $_GET["page"];
    }
    $sodu = mysql_num_rows($result) or die(mysql_error());
    $sotrang = ceil($sodu/$numPage);
    $pageCurrent = (($page*$numPage)-$numPage);
    $sql = "SELECT * FROM users ORDER BY user_id ASC LIMIT {$pageCurrent},{$numPage}";
    $resultPaging = mysql_query($sql);
?>
<div id="content">
    <table class="tablesorter" cellspacing="0">
        <caption><span class="bglink"><a class="link" href="<?=$url["home"] ?>/menu/create"><?php echo $phrase["create"] ?></a></span></caption>
        <thead>
            <tr>
                <th width="30%"><?php echo $phrase["fullname"] ?></th>
                <th width="25%"><?php echo $phrase["email"] ?></th>
                <th width="15%"><?php echo $phrase["phone"] ?></th>
                <th width="15%"><?php echo $phrase["registered"] ?></th>
                <th></th>
            </tr>
        </thead>
<?php 
    while ($rows = mysql_fetch_array($resultPaging)) {
        $i++;
        $date = new DateTime($rows["user_registered"]);
        if($i % 2){
?>      
        <tr>
            <td><?php echo $rows["user_fullname"] ?></td>
            <td><?php echo $rows["user_email"] ?></td>
            <td><?php echo $rows["user_phone"] ?></td>
            <td><?php echo $date->format("d/m/Y") ?></td>
            <th>
                <a href="<?=$url["home"] ?>/menu/update/id/<?php echo $rows["user_id"]?>"><?php echo $phrase["update"] ?></a>|
                <a href="<?=$url["home"] ?>/menu/delete/id/<?php echo $rows["user_id"]?>" onclick="return confirm('Bạn có chắc chắn muốn xóa không.');"><?php echo $phrase["delete"] ?></a>
            </th>
        </tr>
    <?php } else { ?>
        <tr>
            <td><?php echo $rows["user_fullname"] ?></td>
            <td><?php echo $rows["user_email"] ?></td>
            <td><?php echo $rows["user_phone"] ?></td>
            <td><?php echo $date->format("d/m/Y") ?></td>
            <th>
                <a href="<?=$url["home"] ?>/menu/update/id/<?php echo $rows["user_id"]?>"><?php echo $phrase["update"] ?></a>|
                <a href="<?=$url["home"] ?>/menu/delete/id/<?php echo $rows["user_id"]?>" onclick="return confirm('Bạn có chắc chắn muốn xóa không.');"><?php echo $phrase["delete"] ?></a>
            </th>
        </tr>
    <?php } ?>
<?php } ?>
    </table>
    <p style="text-align: center">
        <?php 
            for($i=1; $i <=$sotrang; $i++)
            {
                if($page == $i ){
                    echo "<li class='page'><a class='page-current' href='javascript: void(0)'> [ {$i} ] </a></li>";
                }else{
                    echo "<li class='page-current'><a class='page' href='{$url["home"]}/menu/manager/p/{$i}'> [ {$i} ] </a></li>";
                }
            }
        ?>
    </p>
</div>
<script type="text/javascript">
    $(function() {
            $(".tablesorter").tablesorter({sortList:[[0,0]]});
    });
</script>